package com.carkeeper.servetype.controller;

import com.carkeeper.billpay.feign.PayLogFeign;
import com.carkeeper.entity.Result;
import com.carkeeper.servetype.service.LineChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/linechart")
public class LineChartController {

    @Autowired
    private LineChartService lineChartService;

    /*@Autowired
    private PayLogFeign payLogFeign;*/

    @GetMapping
    public Map getStoreBillReport() {
        Map<String, Object> map = new HashMap<>();
        List<String> days = new ArrayList();
        Calendar calendar = Calendar.getInstance();//获得日历对象，模拟时间就是当前时间
        //计算过去一个月的三十天
        calendar.add(Calendar.DAY_OF_MONTH, -30);//获得当前时间往前推30天的时间
        for (int i = 0; i < 30; i++) {
            calendar.add(Calendar.DAY_OF_MONTH, 1);//获得当前时间往后推一天日期
            Date date = calendar.getTime();
            days.add(new SimpleDateFormat("MM-dd").format(date));
        }
        map.put("days", days);

        List<Integer> storeBillCount = lineChartService.findStoreBillCountByDays(days);
        map.put("storeBillCount", storeBillCount);
        System.out.println("map = " + map);
        return map;
    }

}
